package com.pro.service.impl;

import com.pro.entry.JsComment;
import com.pro.mapper.JsCommentMapper;
import com.pro.service.JsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.logging.Logger;

/**
 * ClassName:JsCommentServiceImple
 * Package:com.pro.service.impl
 * Description:
 *
 * @Date:2022/4/12 15:09
 * @Author: ZPT
 */
@Service
public class JsCommentServiceImple implements JsCommentService {
    @Autowired(required = false)
    private JsCommentMapper commentMapper;

    /**
     * @author ZPT
     * @content :查询评论信息
     */
    @Override
    public List<JsComment> getComment(Integer commodityId, Integer type) {
        List<JsComment> commentList = commentMapper.getComment(commodityId, type);
        for (JsComment comment : commentList) {
            if (comment.getUserType().equals("2")) {
                // 获取后台用户信息
                JsComment user = commentMapper.getUserById(comment.getUserId());
                if (user != null) {
                    // 设置前台用户名字
                    comment.setNickname(user.getNickname());
                    // 设置前台用户头像
                    comment.setAvatarUrl("http://" + user.getAvatarUrl());
                }
            } else {
                // 获取前台用户信息
                JsComment beforeUser = commentMapper.getBeforeUserById(comment.getUserId());
                if (beforeUser != null) {
                    // 设置前台用户名字
                    comment.setNickname(beforeUser.getNickname());
                    // 设置前台用户头像
                    comment.setAvatarUrl("http://" + beforeUser.getAvatarUrl());
                }
            }
        }
        return commentList;
    }
}
